package com.ssyc.gsk_teacher.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.bean.PushCardInfo;

import java.util.List;

/**
 * 排行榜--打卡--列表适配器
 * Created by Administrator on 2018/7/4 0004.
 */

public class PushCardRvAdapter extends BaseQuickAdapter<PushCardInfo.DataBean, BaseViewHolder> {

    private Context context;

    public PushCardRvAdapter(Context context, int layoutResId, @Nullable List<PushCardInfo.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, PushCardInfo.DataBean item) {

        //显示1,2,3位的图标标记,只有条目位置在123时显示
        ImageView ivShowPos = helper.getView(R.id.iv_show_pos);

        //其它位置的文字标识
        TextView tvShowPos = helper.getView(R.id.tv_show_pos);

        if (helper.getLayoutPosition() == 0) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_one);
        } else if (helper.getLayoutPosition() == 1) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_two);
        } else if (helper.getLayoutPosition() == 2) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_three);
        } else {
            ivShowPos.setVisibility(View.GONE);
            tvShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setText((helper.getLayoutPosition() + 1) + "");
        }

        //头像
        RoundedImageView ivHead = helper.getView(R.id.iv_head);
        ImageUtil.displayImage(context, ivHead, item.getSTUDENT_ICON());

        //姓名
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getSTUDENT_NAME());

        //打卡次数
        TextView tvPresent = helper.getView(R.id.tv_size);
        tvPresent.setText(item.getNUM() + "");

        //详情
        Button btDetails = helper.getView(R.id.bt_details);
        btDetails.setBackgroundResource(R.drawable.teacher_look_record);
        btDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到学生端打卡记录界面,将当前学生的账号即user_id携带过去
                ARouter.getInstance().build("/student/StudentPunchCardActivity")
                        .withString("acc", item.getUSER_ID() + "").navigation();
            }
        });
    }
}
